<template>
	<view>
		<stop isBack>
			<view slot="content">随机抽查</view>
		</stop>
		<stab :names="['选择岗位','选择员工','选择项目','记录结果']" v-model="myCurTab"></stab>
		<view class="bcf mart2 pad2" v-show="myCurTab==0">
			<view class="list-style-1">选择岗位</view>
			<view class=" flrc pad2">
				<view class="flex1">{{jobName}}</view>
				<view class="cu-btn line-green lg round" @tap="showSelectList = !showSelectList"> 选择</view>
				<job-selector :multi="false" :show="showSelectList" @onSelect="selectJob" :all="false"></job-selector>
			</view>
		</view>
		<view class="bcf mart2 pad2" v-show="myCurTab==1">
			<view class="list-style-1">相关人员</view>
			<view class="mar2 pos-r" v-for="user in users" :key="user" @tap="selectUser(user)">
				<user-item :iri="user"></user-item>
				<ripple></ripple>
			</view>
			<view class="mar3 pad5 tac bdda " v-if="users.length == 0">暂无相关人员</view>
		</view>
		<view class="bcf mart2 pad2" v-show="myCurTab==2">
			<view class="mart3 pad5 tac bdda"  v-if="points.length == 0">未选择岗位</view>
			<view v-if="points.length > 0">
				<view class="list-style-1">选择考核项目</view>
				<view class="mart5 pos-r" v-for="point in points" :key="point" @tap="selectPoint(point)">
					<job-point-item :iri="point"></job-point-item>
					<ripple></ripple>
				</view>
			</view>
			
		</view>
		<view class="bcf mart2 pad2" v-show="myCurTab==3">
			<view class="mart3 pad5 tac bdda"  v-if="!isbool(selectedPoint)">未选择考核项目</view>
			<job-point-test :iri="selectedPoint" @save="submit" v-if="isbool(selectedPoint)"></job-point-test>
			<view class="mart5" v-if="isbool(selectedPoint)">
				<view class="list-style-2">往期数据</view>
				<view class="mar3 pad5 tac bdda round3 tac" v-if="recent.length == 0">暂无往期数据</view>
				<view class="mart3 lh2 bc13 pad2 round3 shadow1" v-for="item in recent"  :key="item.id">
					<view class="flrc bdbda">
						<view class="flex1 fwb">{{item.title}}</view>
						<view class="fwb fs14">{{item.score}}</view>
					</view>
					<view>
						<text>备注：</text>
						<text>{{item.tips}}</text>
					</view>
					<view class="flrc">
						<view class="flex1">时间：</view>
						<view>{{datetime(item.createAt)}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import JobSelector from '../../../templete/ciming/job_selector.vue'
	import UserItem from '../../../templete/ciming/user_item.vue'
	import JobPointItem from '../../../templete/ciming/job_point_item.vue'
	import JobPointTest from '../../../templete/ciming/job_point_test.vue'
	export default {
		components:{JobSelector,UserItem,JobPointItem,JobPointTest},
		data() {
			return {
				step:1,
				//岗位选择器相关
				showSelectList:false,
				//页面数据
				job:'',
				jobName:'请先选择岗位',
				
				users:[],
				selectedUser:'',
				selectedUserEntity:{},
				
				points:[],
				selectedPoint:'',
				selectedPointEntity:{},
				//近期考核数据
				recent:[],
			}
		},
		methods: {
			selectJob(val,name){
				this.job = val
				this.jobName = name
				this.myCurTab = 1
			},
			selectUser(iri){
				this.selectedUser = iri
				this.myCurTab = 2
			},
			selectPoint(iri){
				this.selectedPoint = iri
				this.myCurTab = 3
				this.$api.getRes(iri,res=>{
					this.selectedPointEntity = res
				})
				this.getRecent()
			},
			submit(data){
				this.log(data)
				data['user'] = this.selectedUser
				data['point'] = this.selectedPoint
				this.$api.post('/api/kpiUserTestPoints',data,res=>{
					this.log(res)
					if(res.s == 1){
						this.$com.showToast('保存成功')
					}
					this.getRecent()
				})
			},
			getRecent(){
				this.$api.get('/api/kpiUserTestPoints',{
					_where:{
						eq:{
							user:this.iriId(this.selectedUser),
							point:this.iriId(this.selectedPoint),
						}
					},
					_order:{
						id:"DESC"
					}
				},res=>{
					this.log(res)
					this.recent = res.d
				})
			}
			
		},
		watch:{
			job(val){
				this.$api.getRes(val,res=>{
					this.log(res)
					this.users = res.users
					this.points = res.points
				})
			}
		}
	}
</script>

<style>

</style>
